package com.hwc.demo.mbs.web;

import javax.servlet.http.HttpSession;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hwc.demo.mbs.bean.entity.User;
import com.hwc.demo.mbs.consts.Constants;
import com.hwc.demo.mbs.consts.ErrorEnum;
import com.hwc.one4all.basebean.BaseResult;

@RestController
public class UserCtrller {
	// 登录
	@PostMapping("/login")
	public BaseResult login(@RequestParam String username, @RequestParam String password, HttpSession session) {
		if (!StringUtils.isEmpty(username) && "123".equals(password)) {
			session.setAttribute(Constants.Manage_Login_Session, username);
			//取去敏数据对象返回
			User user = new User();
			user.setUsername(username);
			return BaseResult.successData(user);
		} else {
			return BaseResult.failErrorEnum(ErrorEnum.MANAGE_LOGIN_ERR);
		}
	}
	
	//登出·注销
	@GetMapping("/logout")
	public BaseResult logout(HttpSession session) {
		session.removeAttribute(Constants.Manage_Login_Session);
		return BaseResult.success();
	}
}
